<template>
  <!-- 派遣薪酬页面 -->
  <div class="page">
    <!-- 搜索页面 -->
    <el-form
      ref="salaryInfoSearch"
      :model="salaryInfoSearch"
      size="small"
      :inline="true"
      class="query-form"
    >
      <el-form-item>
        <el-input
          size="small"
          autocomplete="off"
          v-model="salaryInfoSearch.username"
          placeholder="姓名"
        ></el-input>
      </el-form-item>
       <el-form-item>
            <GridSelect
                title="选择公司名称"
                labelName = 'companyName'
                labelValue = 'id'
                :value = "salaryInfoSearch.companyId"
                :limit="1"
                @getValue='(value) => {salaryInfoSearch.companyId=value}'
                :columns="[
                {
                prop: 'companyName',
                label: '企业名称'
                }
                ]"
                :searchs="[
                {
                prop: 'companyName',
                label: '企业名称'
                }
                ]"
                dataListUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/list"
                entityBeanName="enterpriseInformation"
                queryEntityUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/queryById">
          </GridSelect>
      </el-form-item>
      <el-form-item>
        <el-input
          size="small"
          autocomplete="off"
          v-model="salaryInfoSearch.job"
          placeholder="岗位"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          style="width: 100%"
          v-model="salaryInfoSearchTiem"
          type="monthrange"
          range-separator="-"
          format="yyyy-MM"
          value-format="yyyy-MM"
          start-placeholder="开始月份"
          @change="getSTime"
          end-placeholder="结束月份"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item style="float: right">
        <el-button size="small" type="primary" @click="getSalaryManagement()"
          >查询</el-button
        >
        <el-button
          size="small"
          style="margin-left: 10px"
          @click="resetsearchUsers()"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 内容页面 -->
    <div class="bg-white top">
      <!-- 按钮 -->
      <div style="display: flex">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-circle-close"
          @click="SalaryByUser_add = true"
          >添加</el-button
        >
        <el-button
          size="small"
          type="warning"
          icon="el-icon-circle-close"
          @click="add_out()"
          >下载模板</el-button
        >
        <el-button
          size="small"
          type="danger"
          icon="el-icon-delete"
          @click="deleteCar()"
          :disabled="this.checkSalaryNum == ''"
          >删除</el-button
        >
        <div style="margin-left: 10px">
          <el-upload
            :action="`${this.$http.BASE_URL}/dlyrl/hr/discovery/importDisSalary`"
            :show-file-list="false"
            :headers="{ token: $cookie.get('token') }"
            :on-success="
              (response, file, fileList) => {
                files = fileList
                  .map(
                    (item) => (item.response && item.response.url) || item.url
                  )
                  .join('|');
                $message.success(response.msg);
                this.salaryArra=[];
                this.getSalaryManagement();
              }
            "
            :file-list="salaryArra"
            :limit="1"
            :on-exceed="
              (files, fileList) => {
                $message.warning(
                  `当前限制选择 1 个文件，本次选择了 ${
                    files.length
                  } 个文件，共选择了 ${files.length + fileList.length} 个文件`
                );
              }
            "
          >
            <el-button size="small" type="success" icon="el-icon-circle-close"
              >导入</el-button
            >
          </el-upload>
        </div>
      </div>
      <el-table
        ref="salaryManagement"
        :data="salaryManagement"
        @selection-change="selectioSalaryChang"
        height="calc(100% - 80px)"
        size="small"
        :cell-style="cellStyle"
        style="border: 1px solid #d6cfe2"
        row-key="id"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        class="table"
        :header-cell-class-name="cellHeadStyle"
        :row-class-name="tableRowClassName"
        show-summary
        :summary-method="getSummaries"
        v-loading="salaryLoading"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="salYear"
          label="日期"
          fixed="left"
          show-overflow-tooltip
        ></el-table-column>
         <el-table-column
            prop="userinformation.realName"
            label="姓名"
            fixed="left"
            show-overflow-tooltip
          ></el-table-column>
        <el-table-column label="基本信息">
          <el-table-column
            prop="enterpriseInformation.companyName"
            label="服务公司"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="job"
            label="岗位"
            show-overflow-tooltip
          ></el-table-column>
        </el-table-column>
        <el-table-column label="考勤 (天)">
          <el-table-column
            prop="shouldAttendanceDay"
            label="应出勤"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="travelDays"
            label="出差"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="leaveDays"
            label="请假"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="realityAttendanceDay"
            label="实际出勤"
            show-overflow-tooltip
          ></el-table-column>
        </el-table-column>
        <el-table-column label="固定工资 (元)">
          <el-table-column
            prop="basePay"
            label="基本工资"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="postWage"
            label="岗位工资"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="meritPay"
            label="绩效工资"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="combinedBasic"
            label="固定合计"
            show-overflow-tooltip
          ></el-table-column>
        </el-table-column>
        <el-table-column label="福利待遇 (元)">
          <el-table-column
            prop="seniorityPay"
            label="工龄工资"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="mealAllowance"
            label="餐费补助"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="trafficAllowance"
            label="交通补助"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="commission"
            label="业务提成"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="travelAllowance"
            label="出差补助"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="attendanceBonus"
            label="全勤奖"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="overtime"
            label="加班费"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="communicateSubsidy"
            label="通信补助"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="otherSupport"
            label="其他补助"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="totalWelfareBenefits"
            label="福利合计"
            show-overflow-tooltip
          ></el-table-column>
        </el-table-column>
        <el-table-column
          prop="shouldsalary"
          label="应发工资(元)"
          width="100px"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="扣减项目 (元)">
          <el-table-column
            prop="housingProvidentFund"
            label="公积金"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="party"
            label="党费"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="basicOldAgePension"
            label="基本养老"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="basicMedicalCare"
            label="基本医疗"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="unemploymentInsurance"
            label="失业保险"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="individualIncomeTax"
            label="所得税"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="workInjury"
            label="工伤"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="lately"
            label="迟到"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="leaveearly"
            label="早退"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="absenteeism"
            label="旷工"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="otherDeductions"
            label="其他扣款"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="deductionsCombined"
            label="扣减合计"
            show-overflow-tooltip
          ></el-table-column>
        </el-table-column>
        <el-table-column label="企业保险 (元)">
          <el-table-column
            prop="providentFund"
            label="企业公积金"
            width="110px"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="pension"
            label="企业养老"
            width="110px"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="medical"
            label="企业医疗"
            width="110px"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="unemployment"
            label="企业失业"
            width="110px"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="businessInjury"
            label="企业工伤"
            width="110px"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="otherFee"
            label="企业其他费用"
            width="110px"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="totalFees"
            label="企业费用合计"
            width="110px"
            show-overflow-tooltip
          ></el-table-column>
        </el-table-column>
        <el-table-column
          prop="netPayroll"
          label="实发工资(元)"
          width="100px"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="salaryHandleSize"
        @current-change="salaryHandleCurrent"
        :current-page.sync="salaryInfoPageNo"
        :page-size="salaryInfoPageSize"
        layout="total, prev, pager, next, jumper"
        :total="salaryInfoTotal"
        style="margin: 1rem 0"
      >
      </el-pagination>
      <!-- 新增工资 -->
      <div>
        <el-dialog
          title="添加薪资信息"
          :visible.sync="SalaryByUser_add"
          width="70%"
        >
          <el-form
            ref="addSalaryByUser"
            :model="addSalaryByUser"
            :rules="rule"
            size="small"
          >
            <el-row style="margin-bottom: 10px">
              <el-col
                ><span style="font-size: 14px; color: #2a8bd8"
                  ><i class="el-icon-menu"></i>基本信息：</span
                ></el-col
              >
            </el-row>
            <el-row type="flex">
              <el-col :span="8">
                <el-form-item prop="salYear" label="日期：" label-width="110px">
                  <el-date-picker
                    v-model="addSalaryByUser.salYear"
                    format="yyyy-MM"
                    value-format="yyyy-MM"
                    type="month"
                    placeholder="选择日期"
                    style="width: 100%"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="userinformation" label="姓名：" label-width="110px">
                  <GridSelect
                    title="选择姓名"
                    labelName = 'realName'
                    labelValue = 'id'
                    :value = "addSalaryByUser.userinformation"
                    :limit="1"
                    @getValue='getValues(arguments)'
                    :columns="[
                    {
                        prop: 'realName',
                        label: '用户名'
                    }
                    ]"
                    :searchs="[
                    {
                        prop: 'realName',
                        label: '用户名'
                    }
                    ]"
                    dataListUrl="/dlyrl/hr/discovery/findDisUser"
                    entityBeanName="userInformation"
                    queryEntityUrl="/dlyrl/hr/userinformation/userInformation/queryById">
                    </GridSelect>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="job" label="岗位：" label-width="110px">
                  <el-input
                    v-model="addSalaryByUser.job"
                    autocomplete="off"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row type="flex">
              <el-col :span="8">
                <el-form-item
                  prop="idNumber"
                  label="身份证号："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.idNumber"
                    maxlength="18"
                    disabled
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item prop="phone" label="电话：" label-width="110px">
                  <el-input
                    v-model="addSalaryByUser.phone"
                    maxlength="11"
                    disabled
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  prop="openingbank"
                  label="银行开户行："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.openingbank"
                    :disabled="addSalaryByUser.userinformation==''"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row type="flex">              
              <el-col :span="8">
                <el-form-item
                  prop="bankcard"
                  label="银行卡号："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.bankcard"
                    maxlength="18"
                    :disabled="addSalaryByUser.userinformation==''"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item
                  prop="banknumber"
                  label="银行行号："
                  label-width="110px"
                >
                  <el-input
                  :disabled="addSalaryByUser.userinformation==''"
                    v-model="addSalaryByUser.banknumber"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="margin: 10px 0">
              <el-col
                ><span style="font-size: 14px; font-weight: 500; color: #2a8bd8"
                  ><i class="el-icon-menu"></i>考勤 (天)：</span
                ></el-col
              >
            </el-row>
            <el-row type="flex">
              <el-col :span="4">
                <el-form-item
                  prop="shouldAttendanceDay"
                  label="应出勤："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.shouldAttendanceDay"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="travelDays"
                  label="出差："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.travelDays"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="leaveDays"
                  label="请假："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.leaveDays"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="realityAttendanceDay"
                  label="实际出勤："
                  label-width="110px"
                >
                  <span
                    >{{
                      Number(
                        this.addSalaryByUser.shouldAttendanceDay -
                          this.addSalaryByUser.travelDays -
                          this.addSalaryByUser.leaveDays
                      )
                    }}
                    (天)</span
                  >
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="margin: 10px 0">
              <el-col
                ><span style="font-size: 14px; font-weight: 500; color: #2a8bd8"
                  ><i class="el-icon-menu"></i>基本工资 (元)：</span
                ></el-col
              >
            </el-row>
            <el-row type="flex">
              <el-col :span="4">
                <el-form-item
                  prop="basePay"
                  label="基本工资："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.basePay"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="postWage"
                  label="岗位工资："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.postWage"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="meritPay"
                  label="绩效工资："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.meritPay"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="combinedBasic"
                  label="基本合计："
                  label-width="110px"
                >
                  <span
                    >￥{{
                      Number(this.addSalaryByUser.basePay) +
                      Number(this.addSalaryByUser.postWage) +
                      Number(this.addSalaryByUser.meritPay)
                    }}</span
                  >
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="margin: 10px 0">
              <el-col
                ><span style="font-size: 14px; font-weight: 500; color: #2a8bd8"
                  ><i class="el-icon-menu"></i>福利待遇 (元)：</span
                ></el-col
              >
            </el-row>
            <el-row type="flex">
              <el-col :span="4">
                <el-form-item
                  prop="seniorityPay"
                  label="工龄工资："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.seniorityPay"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="mealAllowance"
                  label="餐费补助："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.mealAllowance"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="trafficAllowance"
                  label="交通补助："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.trafficAllowance"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="commission"
                  label="业务提成："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.commission"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="travelAllowance"
                  label="出差补助："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.travelAllowance"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="attendanceBonus"
                  label="全勤奖："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.attendanceBonus"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row type="flex">
              <el-col :span="4">
                <el-form-item
                  prop="overtime"
                  label="加班费："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.overtime"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="communicateSubsidy"
                  label="通信补助："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.communicateSubsidy"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="otherSupport"
                  label="其他补助："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.otherSupport"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="totalWelfareBenefits"
                  label="福利合计："
                  label-width="110px"
                >
                  <span
                    >￥{{
                      Number(this.addSalaryByUser.seniorityPay) +
                      Number(this.addSalaryByUser.mealAllowance) +
                      Number(this.addSalaryByUser.trafficAllowance) +
                      Number(this.addSalaryByUser.commission) +
                      Number(this.addSalaryByUser.travelAllowance) +
                      Number(this.addSalaryByUser.attendanceBonus) +
                      Number(this.addSalaryByUser.overtime) +
                      Number(this.addSalaryByUser.communicateSubsidy) +
                      Number(this.addSalaryByUser.otherSupport)
                    }}</span
                  >
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="margin: 10px 0">
              <el-col
                ><span style="font-size: 14px; font-weight: 500; color: #2a8bd8"
                  ><i class="el-icon-menu"></i>扣减合计 (元)：</span
                ></el-col
              >
            </el-row>
            <el-row type="flex">
              <el-col :span="4">
                <el-form-item
                  prop="basicOldAgePension"
                  label="基本养老："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.basicOldAgePension"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="basicMedicalCare"
                  label="基本医疗："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.basicMedicalCare"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="unemploymentInsurance"
                  label="失业保险："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.unemploymentInsurance"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="housingProvidentFund"
                  label="公积金："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.housingProvidentFund"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="individualIncomeTax"
                  label="所得税："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.individualIncomeTax"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="lately" label="迟到：" label-width="110px">
                  <el-input
                    v-model="addSalaryByUser.lately"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row type="flex">
              <el-col :span="4">
                <el-form-item
                  prop="leaveearly"
                  label="早退："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.leaveearly"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="absenteeism"
                  label="旷工："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.absenteeism"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item prop="party" label="党费：" label-width="110px">
                  <el-input
                    v-model="addSalaryByUser.party"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="workInjury"
                  label="工伤："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.workInjury"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="otherDeductions"
                  label="其他扣款："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.otherDeductions"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="deductionsCombined"
                  label="扣减合计："
                  label-width="110px"
                >
                  <span
                    >￥{{
                      Number(this.addSalaryByUser.basicOldAgePension) +
                      Number(this.addSalaryByUser.basicMedicalCare) +
                      Number(this.addSalaryByUser.unemploymentInsurance) +
                      Number(this.addSalaryByUser.housingProvidentFund) +
                      Number(this.addSalaryByUser.individualIncomeTax) +
                      Number(this.addSalaryByUser.lately) +
                      Number(this.addSalaryByUser.leaveearly) +
                      Number(this.addSalaryByUser.absenteeism) +
                      +Number(this.addSalaryByUser.party) +
                      Number(this.addSalaryByUser.workInjury) +
                      Number(this.addSalaryByUser.otherDeductions)
                    }}</span
                  >
                </el-form-item>
              </el-col>
            </el-row>
            <!-- 新增的一项 -->
            <el-row style="margin: 10px 0">
              <el-col
                ><span style="font-size: 14px; font-weight: 500; color: #2a8bd8"
                  ><i class="el-icon-menu"></i>企业保险 (元)：</span
                ></el-col
              >
            </el-row>
            <el-row type="flex">
              <el-col :span="4">
                <el-form-item
                  prop="providentFund"
                  label="企业公积金："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.providentFund"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="pension"
                  label="企业养老："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.pension"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="medical"
                  label="企业医疗："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.medical"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="unemployment"
                  label="企业失业："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.unemployment"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="businessInjury"
                  label="企业工伤："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.businessInjury"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="4">
                <el-form-item
                  prop="otherFee"
                  label="企业其他费用："
                  label-width="110px"
                >
                  <el-input
                    v-model="addSalaryByUser.otherFee"
                    autocomplete="off"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row type="flex">
              <el-col :span="4">
                <el-form-item
                  prop="totalFees"
                  label="企业费用合计："
                  label-width="110px"
                >
                  <span
                    >￥{{
                      Number(this.addSalaryByUser.providentFund) +
                      Number(this.addSalaryByUser.pension) +
                      Number(this.addSalaryByUser.medical) +
                      Number(this.addSalaryByUser.unemployment) +
                      Number(this.addSalaryByUser.businessInjury) +
                      Number(this.addSalaryByUser.otherFee)
                    }}</span
                  >
                </el-form-item>
              </el-col>
            </el-row>
            <el-row style="margin-top: 16px; font-weight: 500">
              <el-col :span="6">
                <el-form-item
                  prop="shouldsalary"
                  label="应发工资："
                  label-width="110px"
                >
                  <span
                    >￥{{
                      Number(this.addSalaryByUser.basePay) +
                      Number(this.addSalaryByUser.postWage) +
                      Number(this.addSalaryByUser.meritPay) +
                      (Number(this.addSalaryByUser.seniorityPay) +
                        Number(this.addSalaryByUser.mealAllowance) +
                        Number(this.addSalaryByUser.trafficAllowance) +
                        Number(this.addSalaryByUser.commission) +
                        Number(this.addSalaryByUser.travelAllowance) +
                        Number(this.addSalaryByUser.attendanceBonus) +
                        Number(this.addSalaryByUser.overtime) +
                        Number(this.addSalaryByUser.communicateSubsidy) +
                        Number(this.addSalaryByUser.otherSupport))
                    }}</span
                  >
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item
                  prop="netPayroll"
                  label="实发工资："
                  label-width="110px"
                >
                  <span
                    >￥{{
                      Number(this.addSalaryByUser.basePay) +
                      Number(this.addSalaryByUser.postWage) +
                      Number(this.addSalaryByUser.meritPay) +
                      (Number(this.addSalaryByUser.seniorityPay) +
                        Number(this.addSalaryByUser.mealAllowance) +
                        Number(this.addSalaryByUser.trafficAllowance) +
                        Number(this.addSalaryByUser.commission) +
                        Number(this.addSalaryByUser.travelAllowance) +
                        Number(this.addSalaryByUser.attendanceBonus) +
                        Number(this.addSalaryByUser.overtime) +
                        Number(this.addSalaryByUser.communicateSubsidy) +
                        Number(this.addSalaryByUser.otherSupport)) -
                      (Number(this.addSalaryByUser.basicOldAgePension) +
                        Number(this.addSalaryByUser.basicMedicalCare) +
                        Number(this.addSalaryByUser.unemploymentInsurance) +
                        Number(this.addSalaryByUser.housingProvidentFund) +
                        Number(this.addSalaryByUser.individualIncomeTax) +
                        Number(this.addSalaryByUser.lately) +
                        Number(this.addSalaryByUser.leaveearly) +
                        Number(this.addSalaryByUser.absenteeism) +
                        Number(this.addSalaryByUser.party) +
                        Number(this.addSalaryByUser.workInjury) +
                        Number(this.addSalaryByUser.otherDeductions))
                    }}</span
                  >
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button size="small" @click="SalaryByUser_add = false"
              >取 消</el-button
            >
            <el-button size="small" type="primary" @click="addSalarys()"
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import tableStyles from "../../../../../utils/mixins.js";
import GridSelect from '@/components/gridSelect'
export default {
  mixins: [tableStyles],
  data() {
    var bankAccountValid = (rule, value, callback) => {
      const strBin =
        "10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
      if (!value) {
        return callback(new Error("收款账户不能为空"));
      } else if (!Number.isInteger(+value)) {
        callback(new Error("银行卡号必须全为数字"));
      } else if (value.trim().length < 12 || value.trim().length > 19) {
        callback(new Error("银行卡号长度必须在12到19之间"));
      } else if (strBin.indexOf(value.substring(0, 2)) === -1) {
        callback(new Error("银行卡号开头6位不符合规范"));
      } else {
        callback();
      }
    };
    return {
        salaryArra:[],
      //顶部搜索
      salaryInfoSearchTiem: "",
      salaryInfoSearch: {
        companyId: "",
        username: "",
        job: "",
        beginTime: "",
        endTime: "",
      },
      //批量删除
      checkSalaryNum: [],
      // 导入
      files: "", //导入的文件
      // 薪酬管理存的数据
      salaryManagement: [],
      salaryLoading: null, //加载表格
      // 分页
      salaryInfoPageNo: 1,
      salaryInfoPageSize: 10,
      salaryInfoTotal: 0,

      SalaryByUser_add: false,
      addSalaryByUser: {
        //添加的字段
        salYear: "", //工资年月
        userinformation:"",//姓名
        job: "", //岗位
        idNumber: "", //身份证号
        phone: "", //电话
        bankcard: "", //银行卡号
        openingbank: "", //银行开户行
        banknumber: "", //银行行号

        shouldAttendanceDay: "", //应出勤
        travelDays: "", //出差天数
        leaveDays: "", //请假天数
        realityAttendanceDay: "", //实际出勤天数

        basePay: "", //基本工资
        postWage: "", //岗位工资
        meritPay: "", //绩效工资
        combinedBasic: "", //基本合计

        seniorityPay: "", //工龄工资
        mealAllowance: "", //餐费
        trafficAllowance: "", //交通
        commission: "", //业务提成
        travelAllowance: "", //出差补助
        attendanceBonus: "", //全勤奖
        overtime: "", //加班费
        communicateSubsidy: "", //通信补助
        otherSupport: "", //其他补助
        totalWelfareBenefits: "", //福利合计

        basicOldAgePension: "", //基本养老
        basicMedicalCare: "", //基本医疗
        unemploymentInsurance: "", //失业保险
        housingProvidentFund: "", //住房公积金
        individualIncomeTax: "", //个人所得税
        lately: "", //迟到扣款
        leaveearly: "", //早退扣款
        absenteeism: "", //旷工扣款
        party: "", //党费
        workInjury: "", //工伤扣款
        otherDeductions: "", //其他扣款
        deductionsCombined: "", //扣减合计

        providentFund: "", //企业公积金
        pension: "", //企业养老
        medical: "", //企业医疗
        unemployment: "", //企业失业
        businessInjury: "", //企业工伤
        otherFee: "", //企业其他费用
        totalFees: "", //企业费用合计

        shouldsalary: "", //应发工资
        netPayroll: "", //实发工资
      },
      //校验正确
      rule: {
        salYear: { required: true, message: "请选择日期", trigger: "blur" },
        userinformation: { required: true, message: "请选择用户", trigger: ["blur","change"] },
        // job: { required: true, message: "请输入岗位", trigger: "blur" },
        idNumber: [
          { required: true, message: "请输入身份证号", trigger: "blur" },
          { min: 15, max: 18, message: "请输入正确的身份证", trigger: "blur" },
          {
            required: true,
            pattern:
              /^[1-9][0-9]{5}(18|19|20)[0-9]{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)[0-9]{3}([0-9]|(X|x))/,
            message: "请输入正确的身份证",
            trigger: "blur",
          },
        ],
        phone: [
          { required: true, message: "请输入电话", trigger: "blur" },
          { min: 11, max: 11, message: "请输入正确的电话", trigger: "blur" },
          {
            required: true,
            pattern: /(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/,
            message: "请输入正确的电话",
            trigger: "blur",
          },
        ],
        bankcard: {
          required: true,
          trigger: "blur",
          validator: bankAccountValid,
        },
        openingbank: {
          required: true,
          message: "请输入银行开户行",
          trigger: "blur",
        },
        shouldAttendanceDay: {
          required: true,
          message: "请输入应出勤",
          trigger: "blur",
        },
        travelDays: { required: true, message: "请输入出差", trigger: "blur" },
        leaveDays: { required: true, message: "请输入请假", trigger: "blur" },
        basePay: { required: true, message: "请输入基本工资", trigger: "blur" },
        postWage: {
          required: true,
          message: "请输入岗位工资",
          trigger: "blur",
        },
        meritPay: {
          required: true,
          message: "请输入绩效工资",
          trigger: "blur",
        },
      },
    };
  },
  updated() {	
    this.$nextTick(() => {
        this.$refs['salaryManagement'].doLayout();
    })  
  },
  components: {
      GridSelect,
  },
  mounted() {
    this.getSalaryManagement();
  },
  methods: {
    //进来就获取数据
    getSalaryManagement() {
      this.salaryLoading = true;
      this.$http({
        url: "/dlyrl/hr/discovery/findDispatchSalary",
        method: "get",
        params: {
          pageNo: this.salaryInfoPageNo,
          pageSize: this.salaryInfoPageSize,
          ...this.salaryInfoSearch,
        },
      }).then(({ data }) => {
        if (data && data.success) {
          this.showSummary = true;
          this.salaryManagement = data.salary.list;
          this.salaryInfoTotal = data.salary.count;
        }
        this.salaryLoading = false;
      });
    },
    // 处理选择的时间
    getSTime(val) {
      this.salaryInfoSearchTiem = val;
      this.salaryInfoSearch.beginTime = this.salaryInfoSearchTiem[0];
      this.salaryInfoSearch.endTime = this.salaryInfoSearchTiem[1];
    },
    //重置搜索
    resetsearchUsers() {
      (this.salaryInfoSearchTiem = ""),
        (this.salaryInfoSearch = {
            companyId: "",
            username: "",
            job: "",
            beginTime: "",
            endTime: "",
        }),
        this.getSalaryManagement();
    },
    //下载模板
    add_out() {
      window.location.href =
        "https://admin.dlyrl.com/admin/userfiles/1/userFiles/hr/eventxieban/eventXIeban/2021/2/系统工资模板.xlsx";
    },
    //删除
    deleteCar() {
      let ids = this.checkSalaryNum
        .map((item) => {
          return item.id;
        })
        .join(",");
      this.$confirm(`确定删除所选项吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$http({
          url: "/dlyrl/hr/discovery/delSalary",
          method: "post",
          params: { salaryIds: ids },
        }).then(({ data }) => {
          if (data && data.success) {
            this.$message.success(data.msg);
            this.getSalaryManagement();
          }
        });
      });
    },
    //点击选中的行的select
    selectioSalaryChang(val) {
      this.checkSalaryNum = val;
    },
    //合计方法
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总计";
          return;
        }

        const values = data.map((item) => Number(item[column.property]));

        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += " ";
        } else {
          sums[index] = " ";
        }
      });

      return sums;
    },
    //薪酬管理分页
    salaryHandleSize(val) {
      this.salaryInfoPageSize = val;
      this.salaryInfoPageNo = 1;
      this.getSalaryManagement();
    },
    salaryHandleCurrent(val) {
      this.salaryInfoPageNo = val;
      this.getSalaryManagement();
    },

    //选择完姓名自带数据
    getValues(value){
        this.addSalaryByUser.userinformation=value[0]
        this.$http({
            url: "/dlyrl/hr/userinformation/userInformation/queryById",
            method: "get",
            params: {
              id:this.addSalaryByUser.userinformation
            },
        }).then(({ data }) => {
            if (data && data.success) {
                console.log(data)
                if(data.userInformation.job!=''){
                    this.addSalaryByUser.job=data.userInformation.job;
                }
                if(data.userInformation.idCard!=''){
                    this.addSalaryByUser.idNumber=data.userInformation.idCard;
                }
                if(data.userInformation.phone!=''){
                    this.addSalaryByUser.phone=data.userInformation.phone;
                }
                if(data.userInformation.openingbank!=''){
                    this.addSalaryByUser.openingbank=data.userInformation.openingbank;
                }
                if(data.userInformation.bankcard!=''){
                    this.addSalaryByUser.bankcard=data.userInformation.bankcard;
                }
                if(data.userInformation.banknumber!=''){
                    this.addSalaryByUser.banknumber=data.userInformation.banknumber;
                }
            }
        });
    },
    //添加时执行的方法
    addSalarys() {
        this.$refs.addSalaryByUser.validate((valid) => {
            if (valid) {
                this.addSalaryByUser.realityAttendanceDay = Number(
                    this.addSalaryByUser.shouldAttendanceDay -
                    this.addSalaryByUser.travelDays -
                    this.addSalaryByUser.leaveDays
                );
                this.addSalaryByUser.combinedBasic =
                    Number(this.addSalaryByUser.basePay) +
                    Number(this.addSalaryByUser.postWage) +
                    Number(this.addSalaryByUser.meritPay);
                this.addSalaryByUser.totalWelfareBenefits =
                    Number(this.addSalaryByUser.seniorityPay) +
                    Number(this.addSalaryByUser.mealAllowance) +
                    Number(this.addSalaryByUser.trafficAllowance) +
                    Number(this.addSalaryByUser.commission) +
                    Number(this.addSalaryByUser.travelAllowance) +
                    Number(this.addSalaryByUser.attendanceBonus) +
                    Number(this.addSalaryByUser.overtime) +
                    Number(this.addSalaryByUser.communicateSubsidy) +
                    Number(this.addSalaryByUser.otherSupport);
                this.addSalaryByUser.deductionsCombined =
                    Number(this.addSalaryByUser.basicOldAgePension) +
                    Number(this.addSalaryByUser.basicMedicalCare) +
                    Number(this.addSalaryByUser.unemploymentInsurance) +
                    Number(this.addSalaryByUser.housingProvidentFund) +
                    Number(this.addSalaryByUser.individualIncomeTax) +
                    Number(this.addSalaryByUser.lately) +
                    Number(this.addSalaryByUser.leaveearly) +
                    Number(this.addSalaryByUser.absenteeism) +
                    +Number(this.addSalaryByUser.party) +
                    Number(this.addSalaryByUser.workInjury) +
                    Number(this.addSalaryByUser.otherDeductions);
                this.addSalaryByUser.totalFees =
                    Number(this.addSalaryByUser.providentFund) +
                    Number(this.addSalaryByUser.pension) +
                    Number(this.addSalaryByUser.medical) +
                    Number(this.addSalaryByUser.unemployment) +
                    Number(this.addSalaryByUser.businessInjury) +
                    Number(this.addSalaryByUser.otherFee);
                this.addSalaryByUser.shouldsalary =
                    Number(this.addSalaryByUser.basePay) +
                    Number(this.addSalaryByUser.postWage) +
                    Number(this.addSalaryByUser.meritPay) +
                    (Number(this.addSalaryByUser.seniorityPay) +
                    Number(this.addSalaryByUser.mealAllowance) +
                    Number(this.addSalaryByUser.trafficAllowance) +
                    Number(this.addSalaryByUser.commission) +
                    Number(this.addSalaryByUser.travelAllowance) +
                    Number(this.addSalaryByUser.attendanceBonus) +
                    Number(this.addSalaryByUser.overtime) +
                    Number(this.addSalaryByUser.communicateSubsidy) +
                    Number(this.addSalaryByUser.otherSupport));
                this.addSalaryByUser.netPayroll =
                    Number(this.addSalaryByUser.basePay) +
                    Number(this.addSalaryByUser.postWage) +
                    Number(this.addSalaryByUser.meritPay) +
                    (Number(this.addSalaryByUser.seniorityPay) +
                    Number(this.addSalaryByUser.mealAllowance) +
                    Number(this.addSalaryByUser.trafficAllowance) +
                    Number(this.addSalaryByUser.commission) +
                    Number(this.addSalaryByUser.travelAllowance) +
                    Number(this.addSalaryByUser.attendanceBonus) +
                    Number(this.addSalaryByUser.overtime) +
                    Number(this.addSalaryByUser.communicateSubsidy) +
                    Number(this.addSalaryByUser.otherSupport)) -
                    (Number(this.addSalaryByUser.basicOldAgePension) +
                    Number(this.addSalaryByUser.basicMedicalCare) +
                    Number(this.addSalaryByUser.unemploymentInsurance) +
                    Number(this.addSalaryByUser.housingProvidentFund) +
                    Number(this.addSalaryByUser.individualIncomeTax) +
                    Number(this.addSalaryByUser.lately) +
                    Number(this.addSalaryByUser.leaveearly) +
                    Number(this.addSalaryByUser.absenteeism) +
                    Number(this.addSalaryByUser.party) +
                    Number(this.addSalaryByUser.workInjury) +
                    Number(this.addSalaryByUser.otherDeductions));
                this.$http({
                    url: "/dlyrl/hr/discovery/addSalary",
                    method: "post",
                    params: {
                    ...this.addSalaryByUser,
                    },
                }).then(({ data }) => {
                    if (data && data.success) {
                    this.$message.success(data.msg);
                    this.SalaryByUser_add = false;
                    this.getSalaryManagement();
                    }
                });
            }
         });
    },
  },
};
</script>